package cs304.p3.library.domain;

import java.util.Date;

import cs304.p3.library.util.SqlUtils;

public class BookCopy extends Book {
	private int copyNo;
	private BookStatus status;
	private Borrower borrower;
	private Date outDate;
	/** dueDate is called "inDate" in the DB. */
	private Date dueDate;

	public enum BookStatus {
		ON_HOLD("on-hold"),
		IN("in"),
		OUT("out");

		private String status;

		private BookStatus(String status) {
			this.status = status;
		}

		@Override
		public String toString() {
			return status;
		}
		
		public static BookStatus getBookStatus(String status) {
			for(BookStatus s: BookStatus.values()) {
				if(s.toString().equals(status)) {
					return s;
				}
			}
			return null;
		}
	}
	
	public BookCopy() {
		super();
	}
	
	public BookCopy(String callNumber, int copyNo) {
		super(callNumber, null, null, null, null, 0);
		this.copyNo = copyNo;
		this.status = BookStatus.IN;
	}
	
	public BookCopy(String callNumber, int copyNo, BookStatus status) {
		super(callNumber, null, null, null, null, 0);
		this.copyNo = copyNo;
		this.status = status;
	}
	
	public BookCopy(String callNumber, int copyNo, BookStatus status, Date checkoutDate, Date dueDate) {
		super(callNumber, null, null, null, null, 0);
		this.copyNo = copyNo;
		this.status = status;
		this.outDate = checkoutDate;
		this.dueDate = dueDate;
	}
	
	public BookCopy(String callNumber, String isbn, String title, String mainAuthor, String publisher, int year, int copyNo, BookStatus status) {
		super(callNumber, isbn, title, mainAuthor, publisher, year);
		this.copyNo = copyNo;
		this.status = status;
	}
	
	public void setBorrower(Borrower borrower) {
		this.borrower = borrower;
	}
	
	public Borrower getBorrower() {
		return borrower;
	}
	
	public void setOutDate(Date outDate) {
		this.outDate = outDate;
	}
	
	public Date getOutDate() {
		return outDate;
	}

	public void setCopyNo(int copyNo) {
		this.copyNo = copyNo;
	}

	public int getCopyNo() {
		return copyNo;
	}

	public void setStatus(BookStatus status) {
		this.status = status;
	}

	public BookStatus getStatus() {
		return status;
	}
	
	public Date getDueDate() {
		return dueDate;
	}
	
	public void setDueDate(Date dueDate) {
		this.dueDate = dueDate;
	}
	
	public String toString(){
		StringBuilder builder = new StringBuilder();
		
		builder.append("Copy No. : ");
		builder.append(copyNo);
		builder.append(", Status: ");
		builder.append(status);
		builder.append(", Borrower ID: ");
		//builder.append(borrower.getBid());
		builder.append(", Out Date: ");
		builder.append(SqlUtils.getDateString(outDate));
		builder.append(", Due Date: ");
		builder.append(SqlUtils.getDateString(dueDate));
		
		return builder.toString();
	}
}
